package Slidespresso;

import java.util.ArrayList;
import java.util.Iterator;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;

import XML.XMLWriter;

public abstract class Element {
	String elementName;
	String elementValue;
	ArrayList<Element> list = new ArrayList<Element>();

	Element(String elementName, String elementValue) {
		this.elementName = elementName;
		this.elementValue = elementName;
	}

	public String getElementName() {
		return elementName;
	}

	public void setElementName(String elementName) {
		this.elementName = elementName;
	}

	public String getElementValue() {
		return elementValue;
	}

	public void setElementValue(String elementValue) {
		this.elementValue = elementValue;
	}

	public void addElement(Element el) {
		list.add(el);
	}

	public final void printChildElement()
			throws TransformerConfigurationException,
			ParserConfigurationException {
		//bevat huidig element kindelementen ?
		if (!list.isEmpty()) {
			//beschouw huidig elements als parent 
			XMLWriter.createParentElement(this.elementName);
			//itereer door kindelementen
			Iterator<Element> itr = list.iterator();
			while(itr.hasNext()){
				Element child = itr.next();
				//recursive call
				child.printChildElement();
				//beschouw huidig item als kind element
				XMLWriter.createChildWithValue(child.elementName, child.elementValue);	
			}
			//append kind element aan parent element
			XMLWriter.appendChildElement();
		}
	}
}
